package com.czk.server;

import com.czk.client.NettyClient;
import com.czk.pojo.Invocation;
import com.czk.pojo.Protocol;
import com.czk.pojo.URL;

import java.util.concurrent.ExecutionException;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/8/20 10:45
 */
public class NettyProtocol implements Protocol {
    private NettyClient client;
    @Override
    public void start(URL url) {
        new NettyServer().start(url);
    }

    @Override
    public Object send(URL url, Invocation invocation) {
        if (client == null){
            client=new NettyClient();
        }
        try {
            return client.send(url.getHost(),url.getPort(), invocation);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return null;
    }
}
